Skip to content

feat(sdk): expose the sandbox binding to TypeScript - #402

Open
ItamarZand88 wants to merge 1 commit into
itamar/alien-75-sandbox-5-backendsfrom
itamar/alien-75-sandbox-6-typescript
Open

feat(sdk): expose the sandbox binding to TypeScript#402
ItamarZand88 wants to merge 1 commit into
itamar/alien-75-sandbox-5-backendsfrom
itamar/alien-75-sandbox-6-typescript

Conversation

@ItamarZand88

Copy link
Copy Markdown
Contributor

Summary

Exposes the sandbox binding to TypeScript, so an application written in TypeScript can create a session, run a command, move files and stop it through the same contract the Rust bindings use.

When a TypeScript application asks for a sandbox binding:

  1. The generated N-API layer hands back the same binding the Rust provider resolved.
  2. The SDK wraps it in a typed surface — create, runCommand, readFile, writeFiles, terminate.
  3. A capability the platform does not support is a typed error naming both the platform and the capability, not a silent no-op.

What I did

The published capability set is the interesting part. A portable application cannot assume every backend does everything — preview exists only on AWS, hostname allowlists exist nowhere, and ceilings are enforced on some platforms and refused on others. Rather than let a call fail somewhere deep in a cloud SDK, the capability set is exposed to TypeScript as data, so an application can branch before it calls.

The types are generated from the Rust definitions rather than hand-written, so the two languages cannot drift: the binding JSON is the cross-language contract.

Files touched

  • crates/alien-bindings-node/ — the N-API surface.
  • packages/bindings/src/types.ts — the generated binding types.
  • packages/sdk/src/index.ts — the public export.

How I tested

  • packages/bindings/tests/sandbox.test.ts — the binding shape and the capability set as TypeScript sees them.
  • pnpm generate — confirms the committed types match the Rust definitions; CI fails the build if they drift.

@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

The PR exposes the existing Rust sandbox binding through the Node addon and TypeScript SDK while preserving lazy resolution, typed values, and explicit stream cleanup.

  • Adds N-API handles for sandbox sessions, command streams, file operations, lifecycle operations, and capabilities.
  • Adds the typed TypeScript wrapper and public exports through @alienplatform/bindings and @alienplatform/sdk.
  • Adds wrapper and real-addon tests for streaming, cleanup, environment forwarding, file access, and binding validation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
crates/alien-bindings-node/src/sandbox.rs Adds the thin N-API sandbox facade and an explicit, idempotent command-stream close operation that connects TypeScript iterator cleanup to backend cancellation.
packages/bindings/src/factories.ts Adds lazy typed sandbox wrappers and ensures command streams are closed on normal completion and every early iterator exit.
packages/bindings/src/loader.ts Defines the raw sandbox addon contract consumed by the TypeScript wrapper.
packages/bindings/src/types.ts Publishes session, command-frame, command-options, capability, file, and lifecycle types for sandbox consumers.
packages/sdk/src/index.ts Re-exports the sandbox factory and its public types from the application-facing SDK.
packages/bindings/src/tests/factories.test.ts Verifies lazy command startup, frame streaming, early-exit cleanup, environment forwarding, and file operations.

Sequence Diagram

sequenceDiagram
  participant App as TypeScript application
  participant SDK as @alienplatform/sdk
  participant Wrapper as @alienplatform/bindings
  participant Addon as Node N-API addon
  participant Provider as Rust Sandbox provider
  App->>SDK: sandbox(name)
  SDK->>Wrapper: resolve lazy sandbox facade
  App->>Wrapper: runCommand(session, command, options)
  Wrapper->>Addon: runCommand(...)
  Addon->>Provider: Sandbox::run_command(...)
  Provider-->>Addon: command frame stream
  loop Async iteration
    Wrapper->>Addon: next()
    Addon-->>Wrapper: stdout / stderr / exit frame
    Wrapper-->>App: typed CommandFrame
  end
  App-->>Wrapper: break, return, throw, or completion
  Wrapper->>Addon: close()
  Addon->>Provider: drop output receiver
Loading

Reviews (18): Last reviewed commit: "feat(sdk): expose the sandbox binding to..." | Re-trigger Greptile

Comment thread packages/bindings/src/factories.ts
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 1b99225 to b89ff3c Compare August 11, 2026 21:22
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from b89ff3c to 52bc095 Compare August 11, 2026 21:26
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 52bc095 to 28faa2f Compare August 11, 2026 22:16
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 28faa2f to 57c6f58 Compare August 11, 2026 22:24
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 57c6f58 to aa77872 Compare August 12, 2026 06:32
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from aa77872 to 5a61970 Compare August 12, 2026 06:55
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 5a61970 to 21baedb Compare August 12, 2026 07:05
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 21baedb to 3223ed8 Compare August 12, 2026 07:22
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from 3223ed8 to adf2f66 Compare August 12, 2026 07:49
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from adf2f66 to 3163375 Compare August 12, 2026 08:11
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch 2 times, most recently from 4aec1df to efc05a9 Compare August 12, 2026 09:15
Comment thread packages/bindings/src/factories.ts
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from efc05a9 to cdf38bb Compare August 12, 2026 11:01
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch 2 times, most recently from 235f3a7 to c8dc475 Compare August 12, 2026 12:14
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from c8dc475 to ef250f2 Compare August 12, 2026 13:25
@ItamarZand88
ItamarZand88 force-pushed the itamar/alien-75-sandbox-6-typescript branch from ef250f2 to 34bbffd Compare August 16, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant